package de.koller.caldera.render;

import de.koller.aframe.gl.AFrame;
import de.koller.caldera.CNode;
import de.koller.caldera.render.planets.PlanetRendering;
import de.koller.caldera.render.textures.CTextures;
import de.koller.oceanFramework.tree.Child;
import org.lwjgl.opengl.GL11;

public class CRender extends CNode {
	
	@Child public final CTextures textures = new CTextures();
	private final AFrame frame = new AFrame( 800, 600 );
	
	@Child public final PlanetRendering planets = new PlanetRendering();
	
	@Override
	protected void init() {
		super.init();

		frame.setUp();
		
		GL11.glEnable( GL11.GL_CULL_FACE );
		GL11.glCullFace( GL11.GL_BACK );

		GL11.glEnable( GL11.GL_DEPTH_TEST );
		GL11.glDepthFunc( GL11.GL_LEQUAL );
		
		GL11.glAlphaFunc( GL11.GL_GREATER, 0.01f );
		GL11.glEnable( GL11.GL_ALPHA_TEST );
	}
	
	private void orthoSet() {
		GL11.glMatrixMode( GL11.GL_PROJECTION );
		GL11.glLoadIdentity();

		GL11.glOrtho( 0, 800, 600, 0, -1000, 1000 );
		
		GL11.glMatrixMode( GL11.GL_MODELVIEW );
		GL11.glLoadIdentity();
	}
	
	public void renderGame( int elapsedTime ) {		
		orthoSet();
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
		GL11.glColor3f( 1, 1, 1 );
		
		planets.renderSurfaces();
		planets.renderAtmospheres();
	}

}
